import JSEncrypt from 'jsencrypt';

// 注册方法
const rsaEncrypt = function(str) {
	let pubKey =
		`-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCRcikCBuns3FG0mQQ9KfanUpJ9tFBBBXibv5rPa2NgSKs+7Ck3byWMP0rKt9VbIJjI1tvWOo2V9RUFpczDYA7eLgW9+kowVmJY9rcG7A2UPaTZBZBg+J3hOj9Z7obZgMrx3SVD9ykPH4A8uGdGjn6qvSW6sas8ljbw+snAKJvO8QIDAQAB
  -----END PUBLIC KEY-----`; // ES6 模板字符串 引用 rsa 公钥
	let encryptStr = new JSEncrypt();
	encryptStr.setPublicKey(pubKey); // 设置 加密公钥
	let data = encryptStr.encrypt(str.toString()); // 进行加密
	return data;
}

export default rsaEncrypt
